//
//  WLBaseViewController.swift
//  swiftLiaoNing
//
//  Created by Visitor on 2017/5/12.
//  Copyright © 2017年 万利. All rights reserved.
//

import UIKit

class WLBaseViewController: UIViewController {

     let window = UIApplication.shared.keyWindow
    
    private lazy var spreed: UIActivityIndicatorView = {
        let sp = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray)
        sp.center = CGPoint(x: M_S.width * 0.5, y: M_S.height * 0.5)
        return sp
    }()
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    func setupStyle(){
        view.backgroundColor = .white
        automaticallyAdjustsScrollViewInsets = false
        
        //去掉导航栏底部线
        navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
        navigationController?.navigationBar.shadowImage = UIImage()
        
        let titleBtn = UIBarButtonItem(title: "通信卫士", titleClolr: .white, titleFont: 16)
        navigationItem.leftBarButtonItem = titleBtn
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(customView: lable)
    }
    
     lazy var lable: UILabel = {
        let lab = UILabel()
        lab.frame = CGRect(x: 0, y: 0, width: M_S.width * 0.5  , height: 35)
        lab.backgroundColor = .clear
        lab.textColor = .white
        lab.font = FONT(font: 12)
        lab.textAlignment = .right
        lab.text = "已为20890193人防护"
        return lab
    }()

    func showTextDialog(text: String){
        MBProgressHUD.hideAllHUDs(for: window, animated: true)
        let hud = MBProgressHUD.showAdded(to: self.view, animated: false)
        hud?.removeFromSuperViewOnHide = true
        hud?.mode = MBProgressHUDModeText
        hud?.labelText = text
        hud?.minSize = CGSize(width: 132.0, height: 108.0)
        hud?.hide(true, afterDelay: 1.25)
    }

    func showTextDialogAndAfterDelay(text: String, delay: NSInteger) {
        MBProgressHUD.hideAllHUDs(for: window, animated: true)
        let hud = MBProgressHUD.showAdded(to: self.view, animated: false)
        hud?.removeFromSuperViewOnHide = true
        hud?.mode = MBProgressHUDModeText
        hud?.labelText = text
        hud?.minSize = CGSize(width: 132.0, height: 108.0)
        hud?.hide(true, afterDelay: TimeInterval(delay))
    }
    
    func startWaitDialog(){
        if !spreed.isAnimating {
            spreed.startAnimating()
            window?.addSubview(spreed)
        }
    }
    
    func stopWaitDialog(){
        if spreed.isAnimating {
            spreed.stopAnimating()
            spreed.removeFromSuperview()
        }
    }
    var sHud:MBProgressHUD?
    func startConnectDialog(text: String){
        MBProgressHUD.hideAllHUDs(for: window, animated: true)
        let hud = MBProgressHUD.showAdded(to: self.view, animated: false)
        hud?.removeFromSuperViewOnHide = true
        hud?.mode = MBProgressHUDModeIndeterminate
        hud?.labelText = text
        hud?.minSize = CGSize(width: 132.0, height: 108.0)
        sHud = hud
    }
    
    func stopConnectDialog(){
        MBProgressHUD.hideAllHUDs(for: window, animated: false)
        sHud?.hide(true, afterDelay: 0)
    }
    
    var HUD: MBProgressHUD?
    func startMBProgressHUDWithText(text: String){
        let hud = MBProgressHUD()
        window?.addSubview(hud)
        hud.mode = MBProgressHUDModeIndeterminate
        hud.labelText = text
        hud.show(true)
        HUD = hud
    }
    
    func stopMBProgressHUD(){
        if let HUD = HUD {
            HUD.reloadInputViews()
        }
    }
    
}


